/**
 * 功能描述 列表
 */

define(function (require, exports, module) {
	var Component = require("grid");
	var Dialog = require("dialog");
	var store = require("store");
	var procNonmem = require("../constant/fetchProperties");
	var activeUser = store.get("user");
	var aw = require("ajaxwrapper");
//	var gridDataStatusFormat = require("../store/gridDataStatusFormat");
//	var gridEvents = require("../handler/gridEvents");
	var Form = require("form");
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-grid",	
            	url : "api/nonmembergroup/isverifyquery",
//            	autoRender : false,
				params : function(){
					var subnav = widget.get("subnav");
					var servicePoint = subnav.getValue("servicePoint");
					var time = subnav.getValue("startDate");
					var status = subnav.getValue("status");
					if(status=="Reserve"){
						status = "Confirm,Reserve";
					}else{
						status = "Effective,CheckIn";
					}
					var obj = {
                			"nonMemberGroup.servicePoint" : subnav.getValue("servicePoint"),
                			"nonMemberGroup.checkInDate" : time.start,
                			"nonMemberGroup.checkInDateEnd" : time.end,
                			"nonMemberGroup.signUpType" : "NonMember",
//                			"status" : subnav.getValue("status"),
                			"nonStatus" : status,
                			"orderString" : "nonMemberGroup.checkInDate",
							fetchProperties : procNonmem.fetchProperties
                	};
					
	    			return obj;
				},
				model : {
				 columns  : [{
					 name : "nonMemberGroup.servicePoint.name",
					 label : "目的地"
				 },{
					 name:"nonMemberGroup.contactName",
					 label:"预约人",
					 className: "col-md-2",
				 },{
					 name:"nonMemberGroup.contactPhone",
					 label:"联系电话",
				 },{
					 name : "nonMemberGroup.checkInDate",
					 label : "入住日期",
					 format : "date",
				 },{
					 name : "nonMemberGroup.checkOutDate",
					 label : "退住日期",
					 format : "date"
				 },/*{
					 name : "tourType",
					 label : "散客类型",
					 format:function(value, row){
							return widget.handler.isverifyEvent.nonMenberStatus(row,"体验客户","预约散客团","预约个人","预约会员散客","上门散客团","上门个人","上门会员散客")
     				 }
				 },*/{
					 name:"type",
					 label:"房型(数量)",
					 format:function(value,row){
						 var temp = row.signUpRooms;
						 var str = "";
						 for(var i in temp){
							 if(i == 0 && temp[i].roomType!=null){
								 str =  temp[i].roomType.name + "("+ temp[i].count +")" ;
							 }else{
								 if(temp[i].roomType!=null){
									 str = str + " , " + temp[i].roomType.name + "("+ temp[i].count +")" ;
								 }
							 }
						 }
						 return str;
					 }
				 },{
					 name : "nonMemberGroup.deposit",
					 label : "订金(元)"
				 },/*{
					 name : "groupUnit",
					 label : "组团单位"
				 },{
					 name : "chargeDate",
					 label : "收费日期",
					 format : "date"
				 },*/{
					 name : "nonMemberGroup.status.value",
					 label : "状态",
					 format : function(value, row){
						 if(row.nonMemberGroup.status.key == "Reserve" || row.nonMemberGroup.status.key == "Confirm"){
							 return "待收费";
						 }else{
							 return "已收费";
						 }
					 }
				 },{
						name:"show",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"edit",
							icon:"icon-edit",
							text:"收费",
							show : function(row,data){
								if(data.nonMemberGroup.status.key=="Effective" || data.nonMemberGroup.status.key=="CheckIn"){
									return false;
								}else{
									return true;
								}
							},
							handler:function(index,data,rowEle){
								if(data.nonMemberGroup.chargeDeposit == false){
									Dialog.alert({
				                		title:"提示",
				                		content:"不需要收取订金!"
				                	});
									return false;
								}
								if(data.nonMemberGroup.status.key=="Effective" || data.nonMemberGroup.status.key=="CheckIn"){
									Dialog.alert({
				                		title:"提示",
				                		content:"该状态下，不能再收费了！"
				                	});
									return false;
								}else{
									var remarkForm =new Form({
										parentNode:".J-form-dialog",
										autoRender : false,
						        		model:{
											id:"remarkForm",
											defaultButton:false,
											items:[{
												name:"deposit",
												label:"应收(元)",
												readonly:true,
												defaultValue :data.nonMemberGroup.deposit
											},{
												name:"money",
												label:"实收(元)",
												validate : ["required"],
												 exValidate: function(value) {
									                	var reg = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
							                            if (!reg.test(value)) {
							                                return "请输入正确金额！";
							                            } else {
							                                return true;
							                            }
							                        }
											},{
												name:"checkInDate",
												label:"经办人",
												readonly:true,
												//defaultValue :data.nonMemberGroup.operator.name,
												defaultValue :activeUser.name,
											},{
												name:"chargeDate",
												label:"收费日期",
												type:"date",
												readonly:true,
												defaultValue :moment().format("YYYY-MM-DD"),
											},{
												name:"description",
												label:"备注",
												readonly:true,
												defaultValue :data.nonMemberGroup.description,
											}]
										 }
									});
									widget.set("remarkForm",remarkForm);
									Dialog.showComponent(remarkForm,{
										defaultButton:false,
										title: "散客订金确认",
										setStyle: function(){
											$(".el-dialog-modal .modal").css({
												"top": "10%",
												"width":"50%",
												"left": "25%",
											});
										},
										buttons :[{
											id:"save",
											text:"保存",
											className:"btn-primary",
											handler:function(){
												if(remarkForm.valid()){
													var FormData = remarkForm.getData();
													var saveData = {};
													saveData.pkNonMemberGroup = data.nonMemberGroup.pkNonMemberGroup;
													saveData.money = FormData.money;
													data.money=FormData.money;//把收费的值给data，供查看的时候使用.
//													saveData.startDate = FormData.startDate;
													aw.saveOrUpdate("api/nonmembergroup/pay",aw.customParam(saveData),function(saveData){
														Dialog.close();
									          			widget.get("grid").refresh();
									       			});
												};
											}
										},{
											id:"close",
											text:"取消",
											handler:function(){
												Dialog.close();
											}
										}]
									});
								}
							}
						},{
							id:"cancel",
							icon:"icon-cancel",
							text:"查看",
							handler:function(index,data,rowEle){
								var remarkForm =new Form({
									parentNode:".J-form-dialog",
									autoRender : false,
					        		model:{
										id:"remarkForm",
										defaultButton:false,
										items:[{
											name:"deposit",
											label:"应收(元)",
											readonly:true,
											defaultValue :data.nonMemberGroup.deposit
										},{
											name:"money",
											label:"实收(元)",
											defaultValue :data.nonMemberGroup.money,
											readonly:true,
										},{
											name:"operator",
											label:"经办人",
											readonly:true,
											defaultValue :data.nonMemberGroup.status.key=="Effective" || data.nonMemberGroup.status.key=="CheckIn"?data.nonMemberGroup.operator.name:activeUser.name,
										},{
											name:"chargeDate",
											label:"收费日期",
											type:"date",
											readonly:true,
											defaultValue :data.nonMemberGroup.status.key=="Effective" || data.nonMemberGroup.status.key=="CheckIn"?moment(data.nonMemberGroup.chargeDate).format("YYYY-MM-DD"):moment().format("YYYY-MM-DD"),
										},{
											name:"description",
											label:"备注",
											readonly:true,
											defaultValue :data.nonMemberGroup.description,
										}]
									 }
								});
								widget.set("remarkForm",remarkForm);
								Dialog.showComponent(remarkForm,{
									defaultButton:false,
									title: "散客订金确认",
									setStyle: function(){
										$(".el-dialog-modal .modal").css({
											"top": "10%",
											"width":"50%",
											"left": "25%",
										});
									},
									buttons :[{
										id:"close",
										text:"取消",
										handler:function(){
											Dialog.close();
										}
									}]
								});
								
							}
						}]
					}]
				}
            });
            widget.set("grid", component);
        }
    };
    module.exports = instance;
});
